#!/usr/bin/php
<?php
/*
 *   This file is part of poat.
 *
 *   poat is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat.  If not, see <http://www.gnu.org/licenses/>.
 *   
 *   Copyright (c) 2008 Sergio Gabriel Teves <gabriel.sgt at gmail.com>
 * */

$fpos = strrpos(dirname(__FILE__), "/");
if ($fpos<=0) {
	$fpos = strrpos(dirname(__FILE__), "\\");
}

define('ROOT_PATH',substr(dirname(__FILE__), 0, $fpos)."/");

$FROMLANG = ROOT_PATH."lang/lang_en.inc";
$FROMMAIL = ROOT_PATH."lang/mail_lang_en.inc";

function createPo($fromarray,$out) {
	$today = date('Y-m-d H:iO',time());
	$COPY = "##\r\n# POAT.\r\n# Copyright (C) 2008 Sergio Gabriel Teves\r\n# This file is distributed under the same license as the POAT package.\r\n" .
			"# Sergio Gabriel Teves <gabriel opensuse org>, 2008.\r\n#\r\n";
	$HEADER = "\"Project-Id-Version: POAT\\n\"\r\n\"Report-Msgid-Bugs-To: Sergio Gabriel Teves\\n\"\r\n\"POT-Creation-Date: ".$today."\\n\"\r\n" .
			"\"PO-Revision-Date: ".$today."\\n\"\r\n\"Last-Translator: \\n\"\r\n\"Language-Team: \\n\"\r\n\"MIME-Version: 1.0\\n\"\r\n".
			"\"Content-Type: text/plain; charset=UTF-8\\n\"\r\n\"Content-Transfer-Encoding: 8bit\\n\"\r\n\"X-Generator: POAT\\n\"\r\n\r\n";

	fwrite($out,$COPY);
	$string = "msgid \"\"\r\n";
	$string .= "msgstr \"\"\r\n";
	fwrite($out,$string);
	fwrite($out,$HEADER);
	foreach ($fromarray as $key => $value) {
		$string = "";
		if ($key == "LANGID") {
			$string = "#. language ISO code\r\n";
		}
		$string .= "msgctxt \"".$key."\"\r\n";
		$string .= "msgid \"".str_replace("\n","\\n",html_entity_decode($value,ENT_QUOTES,"UTF-8"))."\"\r\n";
		$string .= "msgstr \"\"\r\n";
		$string .= "\r\n";
		fwrite($out,$string);
	}
}

#LOAD FROM
include($FROMLANG);
$fromarray = $LANG;
unset($LANG);

$out = fopen("pot/poat_lang.pot","w");
createPo($fromarray,$out);
fclose($out);

// MAIL
#LOAD FROM
include($FROMMAIL);
$fromarray = $MAIL;
unset($MAIL);

$out = fopen("pot/poat_mail_lang.pot","w");
createPo($fromarray,$out);
fclose($out);

echo "Done makepot";
?>
